<!DOCTYPE html>
<html lang="en">
<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

		<link href="assets/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="assets/css/font-awesome.min.css" />
		<link rel="stylesheet" href="assets/css/ace.min.css" />
		<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
        <link rel="stylesheet" href="css/style.css"/>
		<script src="assets/js/ace-extra.min.js"></script>
		<script src="js/jquery-1.9.1.min.js"></script>        
        <script src="assets/layer/layer.js" type="text/javascript"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>

<title>登陆</title>
</head>

<body class="login-layout">
<div class="logintop">
    <span>欢迎登陆后台管理界面平台</span>
    <ul>
    <li><a href="#">返回首页</a></li>
    <li><a href="#">帮助</a></li>
    <li><a href="#">关于</a></li>
    </ul>    
    </div>
    <div class="loginbody">
<div class="login-container" id="app">
	<div class="center">
	<h1>
									<i class="icon-leaf green"></i>
									<span class="white">后台管理系统</span>
								</h1>
								<h4 class="white">Background Management System</h4>
							</div>

							<div class="space-6"></div>

							<div class="position-relative" >
								<div id="login-box" class="login-box widget-box no-border visible">
									<div class="widget-body">
										<div class="widget-main">
											<h4 class="header blue lighter bigger">
												<i class="icon-coffee green"></i>
												管理员登陆
											</h4>

											<div class="login_icon"><img src="images/login.png" /></div>


												<fieldset>
													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="text"  v-model.trim="admin.name" >
															<i class="icon-user"></i>
														</span>
													</label>

													<label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password"  v-model.trim="admin.pass" >
															<i class="icon-lock"></i>
														</span>
													</label>
													<span>{{message}}</span>

													<div class="space"></div>

													<div class="clearfix">
														<label class="inline">
															<input type="checkbox" v-model="savePass" class="ace">
															<span class="lbl">保存密码</span>
														</label>

														<button type="button" @click="login"  class="width-35 pull-right btn btn-sm btn-primary" id="login_btn">
															<i class="icon-key"></i>
															登陆
														</button>

													</div>

													<div class="space-4"></div>
												</fieldset>


											<div class="social-or-login center">
												<span class="bigger-110">通知</span>
											</div>

											<div class="social-login center">
											
											</div>
										</div>

										<div class="toolbar clearfix">
											

											
										</div>
									</div>
								</div>
							</div>
						</div>
</div>
<div class="loginbm">版权所有  2016  <a href="">快乐维修文化有限公司</a> </div><strong></strong>
</body>
</html>

<script>
	var app = new Vue({
		el:"#app",
		data:{
			admin:{},
			message:'',
			savePass:false,

		},
		created:function (){


			if(localStorage.getItem("admin")!=null){

				// JSON.parse(localStorage.getItem("localKey");

				axios.post("http://localhost:8080/manage/login",window.localStorage.getItem('admin'))

						.then(res => {
							var token = res.data.data.token;

							this.message = "";
							//登录成功保存token
							window.localStorage.setItem("token", token);
							//从哪个页面跳到的登录，则登录成功后回到哪个页面
							var search = window.location.search;//?url=.....
							if (false) {

								var url = search.slice(3);
								window.location.href = url;
							} else {
								//默认回到首页
								alert("登录成功")
								location.href = "index.html"
							}
						})
			}
		},
		methods: {
			login: function () {

				axios.post("http://localhost:8080/manage/login", this.admin)
						.then(res => {
							var token = res.data.data.token;

							this.message = "";
							//登录成功保存token
							window.localStorage.setItem("token", token);
							//从哪个页面跳到的登录，则登录成功后回到哪个页面
							var search = window.location.search;//?url=.....
							if (false) {

								var url = search.slice(3);
								window.location.href = url;
							} else {
								if (this.savePass) {
									// alert(this.admin+"du")
									console.log(this.admin)
									let obj = JSON.stringify(this.admin)
									//如果选择记住密码，将账号和密码存缓存
									localStorage.setItem("admin", obj)
								}

								//默认回到首页
								alert("登录成功")
								location.href = "index.html"

								localStorage.getItem("tokenAdmin",this.adminLogin);
							}

						})
						.catch(e => {
							console.log(e);
							this.message = "登录失败，请重新登录！";
						});

			},
			 }

	});
</script>